﻿using System;
using Bouyei.Geo.Geometries;
using Bouyei.Geo.GeoParsers.EsirMdb;

namespace Bouyei.Geo.GeoParsers.Parser
{
    /// <summary>
    /// 同时支持esri的.gdb和.mdb的空间信息字节解析
    /// </summary>
    public class EsriMdbParser:IDisposable
    {
        private GeometryReader reader = null;
        private GeometryWriter writer = null;
        public GeoType GeometryType { get; private set; }

        public EsriMdbParser()
        {
            writer = new GeometryWriter();
        }

        public virtual Geometry FromReader(byte[] buffer, int offset = 0)
        {
            using (reader = new GeometryReader(buffer, offset))
            {
                GeometryType = reader.GeometryType;
                return reader.Reader();
            }
        }

        public virtual byte[] ToWriter(Geometry geometry)
        {
           return writer.ToWriter(geometry);
        }

        public void Dispose()
        {
            if(reader != null)
                reader.Dispose();
            writer = null;
        }
    }
}
